< previous page page_452 next page >

Page 452
8694cbadb9b1ef7075903f6f95fc1db2.gif
18: ' the copy routine based on moving 256 bytes at a time
19:     lngFileSize = FileLen(txtSourceFile.Text)
20:     intBufferCount = lngFileSize / 256
21:
22: ' Open the source and destination files
23:     Open txtSourceFile.Text For Binary As #1
24:     Open txtTargetFile.Text For Binary As #2
25:
26: ' This routine loops until the entire file is copied
27:     For intLoopCtr = 1 To intBufferCount + 1
28:         Get #1, , strInByte
29:         Put #2, , strInByte
30:     Next intLoopCtr
31:
32: ' After the copy is complete close both files
33:     Close #1    ' Close file.
34:     Close #2    ' Close file.
35: ' Inform the user that the function is complete
36:     MsgBox Copy function complete, vbInformation
37: End Sub.

For a file copy process, the errors that might occur are as follows
8694cbadb9b1ef7075903f6f95fc1db2.gif
File not found
8694cbadb9b1ef7075903f6f95fc1db2.gif
File already open
8694cbadb9b1ef7075903f6f95fc1db2.gif
Device I/O error
8694cbadb9b1ef7075903f6f95fc1db2.gif
Disk full
8694cbadb9b1ef7075903f6f95fc1db2.gif
Device unavailable
8694cbadb9b1ef7075903f6f95fc1db2.gif
Permission denied
8694cbadb9b1ef7075903f6f95fc1db2.gif
Disk not ready
8694cbadb9b1ef7075903f6f95fc1db2.gif
Path/File access error
8694cbadb9b1ef7075903f6f95fc1db2.gif
Path not found
To handle these errors, you would create a routine that resembles the one in Listing 16.2.
LISTING 16.2. ERROREX1.TXTA SAMPLE ERROR ROUTINE FOR A FILE COPY PROCESS.

8694cbadb9b1ef7075903f6f95fc1db2.gif
 1: FileCopyError:
 2: On Error GoTo 0
 3: Select Case Err.Number
 4:     Case 53 'File not found

 
< previous page page_452 next page >

If you like this book, buy it!